<?
require_once("common/inc.init.php");

// Loading module config
$module = new Module("admin");

// User is allowed to see AdMin?
if(!$user->isEnabledTo("login", $module->id))
{
    header("Location: ". $GLOBALS["CONF"]["url"]["root"]);
    exit();
}

// Preparing lang
$lang = new AdMinLang();
$lang->moduleID = $module->id;

// Modules
$modules = getAllModules();
$extMenu = array();
$arModules = array();
foreach($modules AS $myModule)
{
    if($myModule->hasInterface == "no") continue;
    if ($user->isEnabledTo("read", $myModule->id))
    {
        $url = $myModule->url;
        if(!$myModule->hasJsUi) $nodo["url"] = $url;
        $arModules[] = array("id"         => $myModule->id,
                             "name"       => $myModule->name,
                             "url"        => $myModule->url,
                             "hasJsUi"    => $myModule->hasJsUi,
                             "icon"       => $myModule->ico);
    }
}


// Home module
if ($module->homeModuleID)
{
    $homeModule = new Module($module->homeModuleID);
    if(!$user->isEnabledTo("read", $module->homeModuleID))
    {
        $aLog = new adminLog();
        $aLog->setDBLink($dbLink);
        $aLog->setModule($homeModule->id);
        $aLog->log('read module', $user->getID(), array("status"=>ADMIN_LOG_STATUS_ERROR,
                                                        "start_comment"=>'permission denied'));
        die(ucfirst($lang->translate('access_denied')));
    }
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title><?= $GLOBALS["website"]["name"] ?></title>
    <meta name="description" content="mobile first, app, web app, responsive, admin dashboard, flat, flat ui">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="css/font.css" cache="false">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/plugin.css">
    <link rel="stylesheet" href="css/landing.css">
        <link rel="shortcut icon" href="<?$GLOBALS['CONF']['url']['root']?>/img/favicon.png" type="image/png" />
    <!--[if lt IE 9]>
    <script src="js/ie/respond.min.js" cache="false"></script>
    <script src="js/ie/html5.js" cache="false"></script>
    <script src="js/ie/excanvas.js" cache="false"></script>
    <![endif]-->
    <style>
        @font-face {
          font-family: Engravers;
          src: url("../Font/IE/Engravers_Gothic.eot");
          /* IE9 Compat Modes */
          src: url("../Font/IE/Engravers_Gothic.eot?#iefix") format("embedded-opentype"), url("../Font/Engravers_Gothic.woff") format("woff"), url("../Font/Engravers_Gothic.ttf") format("truetype"), url("../Font/Engravers_Gothic.svg#Engravers_Gothic") format("svg");
          /* Legacy iOS */
        }
        .navbar-brand{
            font-family: Engravers,'Engravers Gothic',Helvetica,Sans-Serif !important;
            padding: 0;
            color: #222222;
            display: block;
            font-weight: normal;
            font-style:normal;
            margin:15px 0 0 10px;
        }
        .navbar-brand:hover,.navbar-brand:focus,.navbar-brand:active{color: #222222;}
    </style>
</head>
<body>
    <!-- header -->
    <header id="header" class="navbar">
        <ul class="nav navbar-nav pull-right">
            <li><a href="<?= $GLOBALS["CONF"]["url"]["admin"] ?>/login.php?action=logout"><?= ucwords($lang->translate('close_session')) ?></a></li>
        </ul>
        <a class="navbar-brand" href="<?=$GLOBALS['CONF']['url']['root']?>/admin" style="padding:0"><b>REVOLUCI&Oacute;N PELOTA</b> ADMIN</a>
        <button type="button" class="btn btn-link pull-left nav-toggle visible-xs" data-toggle="class:slide-nav slide-nav-left" data-target="body">
            <i class="icon-reorder icon-xlarge text-default"></i>
        </button>
    </header>
    <!-- / header -->
    <!-- nav -->
    <nav id="nav" class="nav-primary hidden-xs nav-vertical">
    <ul id="menu" class="nav" data-spy="affix" data-offset-top="50">
        <?
            foreach($arModules as $module)
            {
                $class ='';
                if($module['id']=='portfolio')
                {
                    $class="active";
                    $url=$module['url'];
                }
                ?><li id="<?=$module['id']?>" <?=($class?"class='".$class."'":'')?>><a href="javascript:void(0);" onClick="setUrl('<?=$module['url']?>', '<?=$module['id']?>');"><i class="<?=$module['icon']?> icon-xlarge"></i><span><?=$module['name']?></span></a></li><?
            }
        ?>
    </nav>
    <!-- / nav -->
    <section id="content">
        <section class="main padder">
            <div class="row">
                <div class="col-lg-12">
                    <iframe src="<?=$url?>" style="width: 100%; height:100%; border: none" frameborder="0" id="center-iframe" scrolling="no" onload="resize_iframe('center-iframe');"></iframe>
                </div>
            </div>
        </section>
    </section>
    <!-- / footer -->
    <script src="js/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="js/bootstrap.js"></script>
    <!-- app -->
    <script src="js/app.js"></script>
    <script src="js/app.plugin.js"></script>

    <!-- Sparkline Chart -->
    <script src="js/charts/sparkline/jquery.sparkline.min.js"></script>  
    <!-- Easy Pie Chart -->
    <script src="js/charts/easypiechart/jquery.easy-pie-chart.js"></script>
    <script>
        function setUrl(url, id)
        {
            $('#center-iframe').attr('src',url);
            resize_iframe('center-iframe');
            $('#menu>li.active').removeClass("active");
            $('#'+id).addClass('active');
        }
        
        function resize_iframe(id, param)
        {
            if(param != undefined) the_height = param +150;
            else the_height = document.getElementById(id).contentWindow.document.body.offsetHeight;
            
            console.log(the_height);
            if((the_height==0 || the_height<300)) document.getElementById(id).style.height = '600px';
            else document.getElementById(id).style.height = (the_height+250)+'px';
        }
        
        $("#center-iframe").load(function() { 
            resize_iframe("center-iframe");
        }); 
    </script>
</body>
</html>
